package com.pie4cloud.pie.job.biz.gather.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pie4cloud.pie.common.core.util.R;
import com.pie4cloud.pie.common.log.annotation.SysLog;
import com.pie4cloud.pie.job.api.commons.Constant;
import com.pie4cloud.pie.job.api.entity.ApplyInfo;
import com.pie4cloud.pie.job.biz.gather.service.ApplyInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author feilei
 * @date 2022-01-10 00:54:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/applyinfo" )
@Api(value = "applyinfo", tags = "管理")
public class ApplyInfoController {

    private final ApplyInfoService applyInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param applyInfo 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('gather_applyinfo_get')" )
    public R getApplyInfoPage(Page page, ApplyInfo applyInfo) {
        return R.ok(applyInfoService.page(page, Wrappers.query(applyInfo)));
    }

	/**
	 * 查询所有
	 * @return
	 */
	@ApiOperation(value = "查询所有", notes = "查询所有")
	@GetMapping("/list" )
	@PreAuthorize("@pms.hasPermission('gather_applyinfo_get')" )
	public R list() {
		return R.ok(applyInfoService.list());
	}


    /**
     * 通过id查询
     * @param applyId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{applyId}" )
    @PreAuthorize("@pms.hasPermission('gather_applyinfo_get')" )
    public R getById(@PathVariable("applyId" ) Long applyId) {
        return R.ok(applyInfoService.getById(applyId));
    }

    /**
     * 新增
     * @param applyInfo 
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('gather_applyinfo_add')" )
    public R save(@RequestBody ApplyInfo applyInfo) {
        return R.ok(applyInfoService.save(applyInfo));
    }

    /**
     * 修改
     * @param applyInfo 
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('gather_applyinfo_edit')" )
    public R updateById(@RequestBody ApplyInfo applyInfo) {
        return R.ok(applyInfoService.updateById(applyInfo));
    }


	/**
	 * 审核通过
	 * @param applyId
	 * @return R
	 */
	@ApiOperation(value = "审核通过", notes = "审核通过")
	@SysLog("审核通过" )
	@GetMapping("/verifyPass/{applyId}")
	@PreAuthorize("@pms.hasPermission('gather_applyinfo_edit')" )
	public R verifyPass(@PathVariable("applyId" )  Long applyId) {
		return R.ok(applyInfoService.updateApplyStatusById(applyId, Constant.APPLY_VERIFY_PASS));
	}

	/**
	 * 审核驳回
	 * @param applyId
	 * @return R
	 */
	@ApiOperation(value = "审核驳回", notes = "审核驳回")
	@SysLog("审核驳回" )
	@GetMapping("/verifyFailed/{applyId}")
	@PreAuthorize("@pms.hasPermission('gather_applyinfo_edit')" )
	public R verifyFailed(@PathVariable("applyId" )  Long applyId) {
		return R.ok(applyInfoService.updateApplyStatusById(applyId, Constant.APPLY_VERIFY_FAILED));
	}

	/**
	 * 更新解码信息
	 * @param applyId
	 * @param decodeId
	 * @return R
	 */
	@ApiOperation(value = "更新解码信息", notes = "更新解码信息")
	@SysLog("更新解码信息" )
	@GetMapping("/updateDecodeId/{applyId}/{decodeId}")
	@PreAuthorize("@pms.hasPermission('gather_applyinfo_edit')" )
	public R updateDecodeId(@PathVariable("applyId" )  Long applyId,@PathVariable("decodeId" )  Long decodeId) {
		return R.ok(applyInfoService.updateDecodeIdById(decodeId,applyId));
	}

	/**
	 * 更新FTP信息
	 * @param applyId
	 * @param ftpId
	 * @return R
	 */
	@ApiOperation(value = "更新FTP信息", notes = "更新FTP信息")
	@SysLog("更新FTP信息" )
	@GetMapping("/updateFtpId/{applyId}/{ftpId}")
	@PreAuthorize("@pms.hasPermission('gather_applyinfo_edit')" )
	public R updateFtpId(@PathVariable("applyId" )  Long applyId,@PathVariable("ftpId" )  Long ftpId) {
		return R.ok(applyInfoService.updateFtpIdById(ftpId,applyId));
	}




    /**
     * 通过id删除
     * @param applyId id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SysLog("通过id删除" )
    @DeleteMapping("/{applyId}" )
    @PreAuthorize("@pms.hasPermission('gather_applyinfo_del')" )
    public R removeById(@PathVariable Long applyId) {
        return R.ok(applyInfoService.removeById(applyId));
    }

}
